package demo;

import java.time.LocalDateTime;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.listener.RecordListener;
import com.aerospike.client.policy.QueryPolicy;

public class SyncAndAsyncTest {
	static String namespace = "ns1";
	static String dataSetName = "testset";
	static String binName = "DATA";
	static String key = "SyncAndAsyncTest";
	

	public static void main(String[] args) throws Exception {

		IAerospikeClient client = AsClientUtil.getClient();
		System.out.println("client=" + client);
		
		Key k = new Key(namespace, dataSetName, key);
		
		boolean deleteResult = client.delete(null, k);
		System.out.println("deleteResult="+deleteResult);
		
	    String value = LocalDateTime.now().toString();
	    
	    client.put(null, k, new Bin(binName,value));
	    
	    Record record = client.get(null, k);
	    
	    System.out.println("record="+record);
	    
	    
	    client.get(AsClientUtil.nextEventLoop(), new RecordListenerImpl(), new QueryPolicy(), k);
	    
	    Thread.sleep(3000);
			
		client.close();
		
	}

    private static class RecordListenerImpl implements RecordListener {
        public void onSuccess(Key key, Record record) {
            System.out.println("onSuccess,key=" + key + ",record=" + record);
        }

        public void onFailure(AerospikeException exception) {
            System.out.println("onFailure," + exception);
        }
    }


}
